<?php
class LilcartAppController extends AppController {
	var $helpers = array('Lilcart.Sanitize', 'Lilcart.Lilcart', 'Lilcart.Auth', 'Text', 'Javascript');
	
	function beforeFilter() {
		parent::beforeFilter();
		
		// set language to default
		Configure::write('Config.language', null);

		if (isset($this->Auth)) {
			if ((defined('CAKE_UNIT_TEST') && CAKE_UNIT_TEST) || !@$this->params['admin']) {
				$this->Auth->allow();
			} else {
				$this->Auth->allow('');
			}
		}
	}
	
	function beforeRender() {
		parent::beforeRender();

		$useLayout = Configure::read('LilcartPlugin.useAdminLayout');
		if($useLayout && isset($this->params['prefix']) && $this->params['prefix'] == 'admin') $this->layout = 'admin';
	}
	
	function isAuthorized() {
		return true;
	} 
	
	function redirect($url = null, $status = null, $exit = true) {
		if (defined('CAKE_UNIT_TEST') && CAKE_UNIT_TEST) {
			$old = error_reporting(E_USER_NOTICE);
			trigger_error('redirect:'.Router::url($url, true), E_USER_NOTICE);
			error_reporting($old);
		} else {
			parent::redirect($url, $status, $exit);
		}
	}
	
	function cakeError($method, $messages = array()) {
		if (defined('CAKE_UNIT_TEST') && CAKE_UNIT_TEST) {
			$old = error_reporting(E_USER_NOTICE);
			trigger_error($method, E_USER_NOTICE);
			error_reporting($old);
		} else {
			parent::cakeError($method, $messages);
		}
	}
	
	function error404() {
		$this->cakeError('error404', array());
		
		$this->autoRender = false;
		$this->render(false, 'error');
	}

}

?>